package com.hxzy.common.util;

import com.hxzy.common.enums.AccountTypeEnum;
import com.hxzy.common.util.strategy.PwdErrorLockStrategy;
import com.hxzy.config.autoconfigure.passwordlock.PasswordLockProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 密码验证工厂
 */
@Component
public class PwdExecuteFactory {

    /**
     * 不需要锁定账户算法
     */
    @Autowired
    private PwdErrorLockStrategy pwdErrorAccountUnlockStrategy;

    /**
     * 使用redis实现密码错误账户锁定的算法
     */
    @Autowired
    private PwdErrorLockStrategy pwdErrorRedisLockStrategy;

    /**
     * 自定义属性
     */
    @Autowired
    private PasswordLockProperties  passwordLockProperties;

    public void execute(String password, String hashPassword, Long id, AccountTypeEnum accountTypeEnum){
         PwdErrorLockStrategy  pwdErrorLockStrategy=null;
         if(this.passwordLockProperties.getEnable()){
             pwdErrorLockStrategy=this.pwdErrorRedisLockStrategy;
         }else{
             pwdErrorLockStrategy=this.pwdErrorAccountUnlockStrategy;
         }
         pwdErrorLockStrategy.lockAccount(password,hashPassword,id,accountTypeEnum);
    }


}
